Repository navigation
Clamp out-of-range alpha values in color functions - #581
Open
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
Open
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
Pradeep Ramola (pradeep-ramola) wants to merge 1 commit into
Conversation
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Valid color functions with alpha values outside
[0, 1]currently disappear fromfindDocumentColors. For example,.test { color: rgb(34 89 234 / 150%); }returns no colors instead of an opaque color. Negative alpha values likewise produce no color instead of a transparent one.CSS Color 4 explicitly requires clamping out-of-range alpha at parsed-value time: https://www.w3.org/TR/css-color-4/#alpha-value
The existing alpha parsing shares
getNumericValue's bounded validation and throws on these values, causing color extraction to returnnull.Change
Add an alpha-specific helper that reuses the existing numeric/percentage parser without range rejection, then clamps to
[0, 1]. Use it for the ordinary color-function path and the separatecolor()path.Keep other channel validation, function dispatch, source text/ranges, and unsupported-expression handling unchanged. This is independent of #579 and based directly on current main.
Tests
Added 39 public language-service tests across CSS, LESS, and SCSS:
var()alpha values are not coerced into colors.Before the production fix: 33 failed, 6 controls passed.
Verification on Windows after a clean
npm ci:npm run compile: TypeScript compilation and 7 lint checks passed.node --enable-source-maps --test: 463 passed, no failures/skips.git diff --check: passed.The test files were enumerated explicitly to avoid the single-quoted npm glob selecting no tests in this Windows shell. Full VS Code decorator UI integration was not run.
AI assistance was used to investigate, implement, test, and draft this contribution.